﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DddCms.Presentation.Areas.DddCms.Utility
{
    /// <summary>
    /// http://www.compiledthoughts.com/2011/02/aspnet-mvc-excluding-model-validation.html
    /// Excluding Model Validation Rules
    /// </summary>
    public static class ModelStateCleanAllButExtension
    {
        /// <summary>
        /// Cleans all but.
        /// </summary>
        /// <param name="modelState">State of the model.</param>
        /// <param name="includes">The includes.</param>
        public static void CleanAllBut(this ModelStateDictionary modelState, params string[] includes)
        {
            modelState
              .Where(x => !includes
                 .Any(i => String.Compare(i, x.Key, true) == 0))
              .ToList()
              .ForEach(k => modelState.Remove(k));
        }
    }
}